package com.yan.test;

import java.io.Serial;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author taoge
 * @Date 2024/8/6 16:53
 * @Description
 */
public class Message implements Serializable {
    @Serial
    private static final long serialVersionUID = 875276940908318805L;

    private String dispatcher;
    private String receiver;
    private String messageContent;
    private long sendingTime;

    public Message(String dispatcher, String receiver, String messageContent, long sendingTime) {
        this.dispatcher = dispatcher;
        this.receiver = receiver;
        this.messageContent = messageContent;
        this.sendingTime = sendingTime;
    }

    public Message() {
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getDispatcher() {
        return dispatcher;
    }

    public void setDispatcher(String dispatcher) {
        this.dispatcher = dispatcher;
    }

    public String getReceiver() {
        return receiver;
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    public String getMessageContent() {
        return messageContent;
    }

    public void setMessageContent(String messageContent) {
        this.messageContent = messageContent;
    }

    public long getSendingTime() {
        return sendingTime;
    }

    public void setSendingTime(long sendingTime) {
        this.sendingTime = sendingTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Message message = (Message) o;

        if (sendingTime != message.sendingTime) return false;
        if (dispatcher != null ? !dispatcher.equals(message.dispatcher) : message.dispatcher != null) return false;
        if (receiver != null ? !receiver.equals(message.receiver) : message.receiver != null) return false;
        return messageContent != null ? messageContent.equals(message.messageContent) : message.messageContent == null;
    }

    @Override
    public int hashCode() {
        int result = dispatcher != null ? dispatcher.hashCode() : 0;
        result = 31 * result + (receiver != null ? receiver.hashCode() : 0);
        result = 31 * result + (messageContent != null ? messageContent.hashCode() : 0);
        result = 31 * result + (int) (sendingTime ^ (sendingTime >>> 32));
        return result;
    }

    @Override
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(sendingTime);

        return "Message{" +
                "dispatcher='" + dispatcher + '\'' +
                ", receiver='" + receiver + '\'' +
                ", messageContent='" + messageContent + '\'' +
                ", sendingTime=" + format +
                '}';
    }
}
